const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    name: "",
    mobilePhone: "",
    idCard: ""
  },
  onLoad() {
    if (!app.globalData.userInfo.mobilePhone) {
      wx.showModal({
        title: '温馨提示',
        showCancel: false,
        confirmText: "知道了",
        content: '必须填写快递员信息后才可以接单哦！'
      });
    } else {
      this.setData({
        name: app.globalData.userInfo.name,
        mobilePhone: app.globalData.userInfo.mobilePhone,
        idCard: app.globalData.userInfo.idCard
      });
    }
  },
  formSubmit: function(e) {
    wx.showLoading({
      title: '请稍后...',
      mask: true
    });
    e.detail.value.sessionKey = app.globalData.sessionId;
    wx.request({
      url: app.url.auth,
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: e.detail.value,
      success: function(res) {
        wx.hideLoading();
        const data = res.data;
        if (data.result == "true") {
          app.globalData.userInfo = data.data;
          wx.navigateBack({
            delta: 1
          });
        } else {
          wx.showModal({
            content: data.message,
            showCancel: false,
            success: function(res) {}
          });
        }
      },
      fail: res => {
        wx.hideLoading();
        wx.showModal({
          content: '快递员认证失败!',
          showCancel: false,
          success: function(res) {}
        });
      }
    });
  },
  getMobilePhone: function(e) {
    console.log(e);
  }
})